// src/main/index.ts
import 'reflect-metadata'
import { NestFactory } from '@nestjs/core'
import { ElectronModule } from '@main/app/electron.module'
import { DbInitService } from '@main/services/db-init.service'
import { config } from 'dotenv'
import setupPaths from '@main/settings/paths'
import { LogService } from '@main/services/log.service'

config()
setupPaths()

async function bootstrap() {
  const app = await NestFactory.create(ElectronModule, { logger: false }) // 使用自定义 logger
  await app.init()

  // 🔍 调试：检查服务是否可获取
  try {
    const logService = app.get(LogService)
    console.log('✅ LogService 获取成功', logService)

    const dbService = app.get(DbInitService)
    console.log('✅ DbInitService 获取成功', dbService) // 应该是 true

    await dbService.initialize()
  } catch (err) {
    console.error('❌ 获取服务失败:', err)
  }
}

bootstrap().catch((err) => {
  console.error('❌ Failed to start Electron app:', err)
})
